-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add two new diagnostics: one for mismatch in generic arguments count, and another for mismatch in their kind #19479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ee1a69e
to
abc50a7
Compare
107dbaa
to
8de5777
Compare
|
||
/// This function find the AST fragment that corresponds to an `AssociatedTypeBinding` in the HIR. | ||
pub fn hir_assoc_type_binding_to_ast( | ||
segment_args: &ast::GenericArgList, | ||
binding_idx: u32, | ||
) -> Option<ast::AssocTypeArg> { | ||
segment_args | ||
.generic_args() | ||
.filter_map(|arg| match arg { | ||
ast::GenericArg::AssocTypeArg(it) => Some(it), | ||
_ => None, | ||
}) | ||
.filter(|binding| binding.param_list().is_none() && binding.name_ref().is_some()) | ||
.nth(binding_idx as usize) | ||
} | ||
|
||
/// This function find the AST generic argument from the one in the HIR. Does not support the `Self` argument. | ||
pub fn hir_generic_arg_to_ast( | ||
args: &ast::GenericArgList, | ||
arg_idx: u32, | ||
has_self_arg: bool, | ||
) -> Option<ast::GenericArg> { | ||
args.generic_args() | ||
.filter(|arg| match arg { | ||
ast::GenericArg::AssocTypeArg(_) => false, | ||
ast::GenericArg::LifetimeArg(arg) => arg.lifetime().is_some(), | ||
ast::GenericArg::ConstArg(_) | ast::GenericArg::TypeArg(_) => true, | ||
}) | ||
.nth(arg_idx as usize - has_self_arg as usize) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming nit (also the location for them seems unrelated), these don't touch anything hir related
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hir
is against the ast
: it finds the AST for the HIR lowered.
#19624 will probably collide with this once merged |
8de5777
to
813a461
Compare
… and another for mismatch in their kind Also known as E0747 and E0107. And by the way, rewrite how we lower generic arguments and deduplicate it between paths and method calls. The new version is taken almost straight from rustc. This commit also changes the binders of `generic_defaults()`, to only include the binders of the arguments up to (and not including) the current argument. This make it easier to handle it in the rewritten lowering of generic args. It's also how rustc does it.
It's cute, isn't it?
813a461
to
7b8200b
Compare
Alright, rebased and addressed comments. |
Also known as E0747 and E0107.
And by the way, rewrite how we lower generic arguments and deduplicate it between paths and method calls. The new version is taken almost straight from rustc.
This commit also changes the binders of
generic_defaults()
, to only include the binders of the arguments up to (and not including) the current argument. This make it easier to handle it in the rewritten lowering of generic args. It's also how rustc does it.This is a step towards #17590, the next step will be to add a quickfix to the count mismatch diagnostic that adds new parameters. Since this became somewhat big I separated the steps.